//
//  PickViewController.m
//  Hai
//
//  Created by admin on 16/3/8.
//  Copyright © 2016年 wangzijian. All rights reserved.
//

#import "DayPickViewController.h"
@interface DayPickViewController ()
@end

@implementation DayPickViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.5];
    self.pickview.dataSource =self;
    self.pickview.delegate =self;
    [self initPickerData];
    [self pickerView:self.pickview didSelectRow:0 inComponent:0 ];
    [self pickerView:self.pickview didSelectRow:0 inComponent:1 ];
}
//初始化PickerView使用的数据源
-(void)initPickerData{
      [self loaddata];
}

#pragma mark-  加载性别选择数据
- (void)loaddata{
    _arrayData =[NSArray arrayWithObjects: @"1天", @"2天", @"3天", @"4天", @"5天", @"6天", @"7天", @"8天", @"9天", @"10天", @"11天", @"12天", @"13天", @"14天", @"15天", @"16天", @"17天", @"18天", @"19天", @"20天", @"21天", @"22天", @"23天", @"24天", @"25天", @"26天", @"27天", @"28天", @"29天", @"30天", @"31天",nil];
}



#pragma mark  --- delegate 视图委托 ---
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView{
        return 1;
}


- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component{
        return [_arrayData count];
    
}
- (CGFloat)pickerView:(UIPickerView *)pickerView rowHeightForComponent:(NSInteger)component{
    return 38;
}
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{

        _dayData =_arrayData[row];
        _dayDataIndex = [NSString stringWithFormat:@"%ld",row+1];
    
}
-(NSString *)pickerView:(UIPickerView *)pickerView
            titleForRow:(NSInteger)row forComponent:(NSInteger)componen{
 
        return [_arrayData objectAtIndex:row];

}

- (IBAction)tapcancel:(id)sender {
//    _dayData=@"1天";
//    _dayDataIndex=@"1";
//    if (([self.dayDataDelegate respondsToSelector:@selector(sendDayData:dayDataIndex:)])) {
//        [self.dayDataDelegate sendDayData:_dayData dayDataIndex:_dayDataIndex];
//    }
    [self removeview];
}
- (IBAction)tapconfirm:(id)sender {
   if (([self.dayDataDelegate respondsToSelector:@selector(sendDayData:dayDataIndex:)])) {
        [self.dayDataDelegate sendDayData:_dayData dayDataIndex:_dayDataIndex];
    }
    [self removeview];
}
- (IBAction)tapbackground:(id)sender {
//    if (([self.dayDataDelegate respondsToSelector:@selector(sendDayData:dayDataIndex:)])) {
//        [self.dayDataDelegate sendDayData:_dayData dayDataIndex:_dayDataIndex];
//    }
    [self removeview];
}
- (void)removeview{
    [self.view removeFromSuperview];
    [self removeFromParentViewController];
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
